<template>
	<view class="courseDetail">
		<view class="nav_bar">
			<uni-nav-bar statusBar fixed :border="false" @clickLeft="back">
				<block slot="left">
					<view class="back_btn">
						<uni-icons type="back" color="#fff" size="20"></uni-icons>
					</view>
				</block>
			</uni-nav-bar>
		</view>
		<view class="detail_t">
			<view class="banner">
				<swiper class="swiper" circular :indicator-dots="false" autoplay :interval="3000" :duration="500"
					@change="swiperChange">
					<block v-for="(item,i) in list" :key="i">
						<swiper-item>
							<view class="swiper-item">
								<image :src="item" mode="aspectFill"></image>
							</view>
						</swiper-item>
					</block>
				</swiper>
				<view class="custom-dots">{{currentSwiper}}/{{list.length}}</view>
			</view>
			<view class="course_info">

				<view class="course_base_info">
					<view class="info_1">
						<view class="course_title">{{details.title}}</view>
						<view class="price">
							<text>￥</text>
							<text class="price_val">{{details.money}}</text>
						</view>
					</view>
					<view class="info_2">
						时间：{{details.startTime}}
					</view>
					<view class="info_3">
						<text>地址：{{details.address}}</text>
						<uni-icons type="location-filled" color="#999999" size="16"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="course_other_info">
			<view class="tabs">
				<block v-for="item in tabs" :key="item.val">
					<view class="tab_item" @tap="currentTab=item.val">
						<view class="tab_name" :class="{'active_name':currentTab==item.val}">{{item.name}}</view>
						<image src="../static/b.png" mode="" v-if="currentTab==item.val"></image>
					</view>
				</block>
			</view>

			<view class="course_desc" v-if="currentTab==1">
				<rich-text :nodes="nodes"></rich-text>
			</view>
			<view class="evaluateTalk" v-else>
				<view class="talk">
					<view class="talk_t">
						<view class="author">
							<image src="../../../static/img/active-bg.png" mode=""></image>
							<view class="">
								<view class="author_name">七里香</view>
								<view class="time">2023-11-12 14:30</view>
							</view>
						</view>
					</view>
					<view class="talk_b">
						<view class="article_text">
							小朋友在这次活动中 表现的非常给力，快来看看本期活动 有您家的小朋友吗？
						</view>
						<view class="article_imgs">
							<block v-for="img in 3" :key="img">
								<image src="../../../static/img/active-bg.png" mode="" @tap="previewImg"></image>
							</block>
						</view>
					</view>
				</view>
				<view class="comment_list">
					<view class="title">全部评论</view>
					<view class="list">
						<block v-for="item in 6" :key="item">
							<view class="item">
								<view class="avatar">
									<image src="../../../static/img/active-bg.png" mode=""></image>
								</view>
								<view class="comment_info">
									<view class="comment_top">
										<view class="">
											<view class="user_name">张三</view>
											<view class="time">07-02 21:28</view>
										</view>
										<view class="likes">
											<uni-icons type="heart" size="18"></uni-icons>
											<text>256</text>
										</view>
									</view>
									<view class="comment_text">
										这款我也买过 ，非常不错,这款我也买过 ，非常不错
									</view>
								</view>

							</view>
						</block>
					</view>
				</view>
				<view class="send_box" :style="'bottom:'+keyboardHeight+'rpx;'">
					<view class="input_box">
						<textarea name="" :adjust-position="false" :style="'height:'+textareaHeight+'rpx;'"
							v-model="content" @input="inputMsg"></textarea>
						<view class="msg_text">{{content}}</view>
					</view>
					<view class="send_btn">发送</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				details: {},
				list: [],
				currentSwiper: 1,
				tabs: [{
					name: '产品介绍',
					val: 1
				}, {
					name: '课程评价',
					val: 2
				}],
				currentTab: 1,
				content: '',
				textareaHeight: 74,
				keyboardHeight: 0,
				nodes: '',
			};
		},
		onLoad(opt) {
			this.id = opt.id
			this.getDetails()
			uni.onKeyboardHeightChange(res => {
				const {
					windowWidth,
					windowHeight
				} = uni.getSystemInfoSync()
				this.keyboardHeight = Math.round(res.height * (750 / windowWidth))
			})
		},
		methods: {
			async getDetails() {
				const res = await this.$api.get('ebTrusteeshipCourse/details', {
					id: this.id
				});
				const {
					code,
					data
				} = res
				if (code == 200) {
					var str = data.details;
					str = str.replace(/wscnph/g, 'wscnph maxImg');
					str = str.replace(/<img/g, '<img style="max-width:100% !important;height:auto;"');
					this.nodes = str;
					this.details = data
					this.list = data.picture.split(',')
					console.log(res, "tiem--", this.list)
				}
			},
			swiperChange(e) {
				this.currentSwiper = e.detail.current + 1;
			},
			inputMsg() {
				var timer = setTimeout(() => {
					this.$nextTick(() => {
						uni.createSelectorQuery().select('.msg_text').boundingClientRect(res => {
							this.textareaHeight = Math.round(res.height * (750 / res.width));
						}).exec();
					})
					clearTimeout(timer)
				}, 1000)
			},
			previewImg() {
				uni.previewImage({
					current: 0,
					urls: ['../../../static/img/active-bg.png'],
				});
			},
			async getComment() {
				const res = await this.$api.post('community/note/add')
			}
		}
	}
</script>

<style lang="scss">
	p {
		text-indent: 2em;
	}
	.courseDetail {
		.nav_bar {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			right: 0;
			z-index: 99;

			/deep/.uni-navbar {
				// opacity: 0;
				.uni-navbar__content {
					background-color: transparent !important;

					.uni-navbar__header {
						background-color: transparent !important;
					}
				}
			}

			.back_btn {
				width: 54rpx;
				height: 54rpx;
				border-radius: 50%;
				display: flex;
				justify-content: center;
				align-items: center;
				background-color: rgba(0, 0, 0, 0.4);
			}
		}

		.detail_t {
			width: 100%;
			height: 728rpx;
			position: relative;
			border-bottom: 14rpx solid #F7F7F7;

			.banner {
				position: relative;

				.swiper {
					width: 100%;
					height: 608rpx;

					.swiper-item {
						image {
							width: 100%;
							height: 608rpx;
						}
					}
				}

				.custom-dots {
					width: 66rpx;
					height: 34rpx;
					border-radius: 17rpx;
					line-height: 34rpx;
					text-align: center;
					background-color: rgba(0, 0, 0, 0.4);
					color: #fff;
					font-size: 24rpx;
					position: absolute;
					right: 26rpx;
					bottom: 80rpx;
					z-index: 9;
				}
			}

			.course_info {
				width: 100%;
				height: 100%;
				position: absolute;
				left: 0;
				right: 0;
				bottom: 0;
				top: 0;
				z-index: 9;
				display: flex;
				align-items: flex-end;



				.course_base_info {
					width: 100%;
					height: 182rpx;
					border-radius: 60rpx 60rpx 0 0;
					background-color: #fff;
					padding: 30rpx 28rpx 0;
					box-sizing: border-box;

					.info_1 {
						display: flex;
						justify-content: space-between;
						align-items: center;

						.course_title {
							font-size: 32rpx;
							font-weight: bold;
							line-height: 32rpx;
						}

						.price {
							font-size: 24rpx;
							font-weight: bold;
							color: #FF0404;

							.price_val {
								font-size: 40rpx;
							}
						}
					}

					.info_2,
					.info_3 {
						font-size: 24rpx;
						color: #999999;
						display: flex;
						align-items: center;
						line-height: 24rpx;
					}

					.info_2 {
						padding: 22rpx 0 12rpx;
					}
				}
			}
		}

		.course_other_info {

			.tabs {
				padding: 34rpx 108rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.tab_item {
					display: flex;
					flex-direction: column;
					align-items: center;

					.tab_name {
						font-size: 26rpx;
					}

					.active_name {
						font-size: 32rpx;
						font-weight: bold;
						color: #2E80FE;
					}

					image {
						width: 36rpx;
						height: 14rpx;
					}
				}
			}

			.course_desc {
				padding: 0 26rpx;
				box-sizing: border-box;
			}
		}

		.evaluateTalk {
			.talk {
				padding: 26rpx 40rpx 40rpx;
				box-sizing: border-box;
				border-radius: 20rpx;
				background-color: #fff;
				border-bottom: 20rpx solid #F7F7F7;

				.talk_t {
					display: flex;
					justify-content: space-between;
					margin-bottom: 20rpx;

					.author {
						display: flex;
						align-items: center;

						image {
							width: 80rpx;
							height: 80rpx;
							border-radius: 50%;
							margin-right: 14rpx;
						}

						.author_name {
							font-size: 30rpx;
							line-height: 30rpx;
							font-weight: bold;
							margin-bottom: 14rpx;
						}

						.time {
							font-size: 24rpx;
							line-height: 24rpx;
							color: #B3B3B3;
						}
					}
				}

				.talk_b {
					.article_text {
						font-size: 26rpx;
						line-height: 40rpx;
						margin-bottom: 16rpx;
					}

					.article_imgs {
						image {
							width: 206rpx;
							height: 200rpx;
							border-radius: 20rpx;
						}

						image:not(:last-child) {
							margin-right: 12rpx;
						}
					}
				}
			}

			.comment_list {
				padding: 40rpx 40rpx 120rpx;
				box-sizing: border-box;

				.title {
					font-size: 26rpx;
					font-weight: bold;
					margin-bottom: 48rpx;
				}

				.list {
					.item {
						display: flex;
						justify-content: space-between;
						margin-bottom: 60rpx;

						.avatar {
							image {
								width: 66rpx;
								height: 66rpx;
								border-radius: 50%;
							}
						}

						.comment_info {
							flex: 1;
							margin-left: 20rpx;

							.comment_top {
								display: flex;
								justify-content: space-between;

								.user_name {
									font-size: 26rpx;
									line-height: 30rpx;
								}

								.time {
									font-size: 20rpx;
									line-height: 20rpx;
									color: #B3B3B3;
									padding: 10rpx 0;
								}

								.likes {
									padding-top: 34rpx;
									display: flex;
									align-items: center;

									>text {
										font-size: 24rpx;
										line-height: 24rpx;
										margin-left: 10rpx;
									}
								}
							}



							.comment_text {
								font-size: 26rpx;
								line-height: 32rpx;
							}
						}


					}
				}
			}

			.send_box {
				width: 100%;
				padding: 20rpx 26rpx 40rpx;
				box-sizing: border-box;
				background-color: #fff;
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
				position: fixed;
				left: 0;
				right: 0;
				bottom: 0;
				z-index: 5;

				.input_box {
					width: 534rpx;
					min-height: 74rpx;
					position: relative;
					background-color: #F5F5F5;
					border-radius: 14rpx;

					textarea {
						width: 534rpx;
						min-height: 74rpx;
						padding: 16rpx 20rpx;
						box-sizing: border-box;
						font-size: 28rpx;
						line-height: 30rpx;
						position: absolute;
						left: 0;
						top: 0;
						right: 0;
						z-index: 9;
					}

					.msg_text {
						width: 534rpx;
						min-height: 74rpx;
						padding: 16rpx 20rpx;
						box-sizing: border-box;
						font-size: 28rpx;
						line-height: 30rpx;
						opacity: 0;
					}
				}

				.send_btn {
					width: 130rpx;
					height: 74rpx;
					border-radius: 14rpx;
					text-align: center;
					line-height: 74rpx;
					background-color: #2E80FE;
					font-size: 26rpx;
					color: #FFFFFF;
				}
			}
		}
	}
</style>